Skip to content

Get directions using fetch #5642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Conversation

hlfan
Copy link
Contributor

@hlfan hlfan commented Feb 10, 2025

Start to move from $.ajax to fetch with the thing I recently restructured.

@HolgerJeromin
Copy link
Contributor

This pushes json parsing off the js main thread. Hurray

@hlfan
Copy link
Contributor Author

hlfan commented Feb 10, 2025

Actually needs to be abortable...

@hlfan hlfan marked this pull request as draft February 10, 2025 17:34
@hlfan hlfan force-pushed the fetch-directions branch 2 times, most recently from 078e013 to 3d83b11 Compare February 11, 2025 10:12
@hlfan
Copy link
Contributor Author

hlfan commented Feb 11, 2025

I still don't know what I need to change in the testing stub

@hlfan hlfan marked this pull request as ready for review February 11, 2025 10:21
@HolgerJeromin
Copy link
Contributor

I still don't know what I need to change in the testing stub

I would guess:

  def stub_straight_routing(start_instruction: "Start here", finish_instruction: "Finish there")
    stub_routing <<~CALLBACK
      const distance = points[0].distanceTo(points[1]);
      const time = distance * 30;
      return Promise.resolve({
        line: points,
        steps: [
          [points[0],  8, "<b>1.</b> #{start_instruction}", distance, points],
          [points[1], 14, "<b>2.</b> #{finish_instruction}", 0, [points[1]]]
        ],
        distance,
        time
      });
    CALLBACK
  end

  def stub_routing(callback_code)
    execute_script <<~SCRIPT
      $(() => {
        for (const engine of OSM.Directions.engines) {
          engine.getRoute = (points, signal) => {
              #{callback_code}
          };
        }
      });
    SCRIPT
  end
end

Co-authored-by: Holger Jeromin <h.jeromin@beckhoff.com>
Copy link
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - this looks good now I think.

@tomhughes tomhughes merged commit cb0c526 into openstreetmap:master Feb 12, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants